import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import { ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { TypeDto } from './dto/type.dto';
import { TypeService } from './type.service';

@Controller()
@ApiTags('文章分类')
export class TypeController {
    constructor(private readonly typeService: TypeService) {}

    @Get('type')
    typeList() {
        return this.typeService.getAllType()
    }

    @Get('type/:typeId')
    @ApiParam({
        name: 'typeId',
        description: '请传入文章类型Id'
    })
    getTypeById(@Param('typeId') id){
        return this.typeService.getTypeById(id)
    }

    @Post('type')
    createType(@Body() type: TypeDto){
        return this.typeService.saveType(type);
    }

    @Put('type/:typeId')
    @ApiParam({
        name: 'typeId',
        description: '请传入文章类型Id' 
    })
    updateTypeById(@Param('typeId') id: number, @Body() updateTypeDto: TypeDto){
        return this.typeService.updateTypeById(id, updateTypeDto)
    }

    @Delete('type/:typeId')
    @ApiParam({
        name: 'typeId',
        description: '请传入文章类型Id' 
    })
    deleteTypeById(@Param('typeId') id){
        return this.typeService.deleteTypeById(id)
    }

    @Get('typeByQuery')
    @ApiQuery({
        name: 'query',
        required: false
    })
    @ApiQuery({
        name: 'pagenum'
    })
    @ApiQuery({
        name: 'pagesize'
    })
    getTypeListByQuery(@Query('query') query, @Query('pagenum') pagenum, @Query('pagesize') pagesize){
        return this.typeService.getTypeByQuery(query, pagenum, pagesize)
    }
}
